-
Notifications
You must be signed in to change notification settings - Fork 192
helper functions for Filesystem error handling #1015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for this PR @wassup05. Question: is there a reason for using UPPER_CASE ? The style guide promotes snake_case for procedures and constants. |
Oh no, It was just because it was an error and I felt it was better to emphasize that, but I'll change it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces two helper functions fs_error
and fs_error_code
to simplify filesystem error handling in the stdlib_system module. These functions provide convenient ways to create state_type
objects with the STDLIB_FS_ERROR
flag set.
- Adds
fs_error
function that accepts up to 20 optional arguments and creates a filesystem error state - Adds
fs_error_code
function that prefixes an error code to the message and accepts up to 19 additional arguments - Includes comprehensive tests, documentation, and example code
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/stdlib_system.F90 |
Implements the two new helper functions and adds required imports |
test/system/test_filesystem.f90 |
Adds unit tests for both helper functions |
doc/specs/stdlib_system.md |
Documents the new functions with detailed specifications |
example/system/example_fs_error.f90 |
Provides usage examples for both functions |
example/system/CMakeLists.txt |
Registers the new example in the build system |
Comments suppressed due to low confidence (2)
test/system/test_filesystem.f90:25
- The subroutine name
test_fs_error
is inconsistent with the test nametest_FS_ERROR
used innew_unittest
. Consider renaming totest_FS_ERROR
for consistency.
subroutine test_fs_error(error)
doc/specs/stdlib_system.md:472
- The syntax example shows
fs_error
but should befs_error_code
since this is documenting thefs_error_code
function.
`err = fs_error(code [, a1,a2,a3,a4...... a19])`
src/stdlib_system.F90
Outdated
pure function fs_error_code(code,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, & | ||
a11,a12,a13,a14,a15,a16,a17,a18, a19) result(state) | ||
|
||
type(state_type) :: state | ||
!> Platform specific error code | ||
integer, intent(in) :: code | ||
!> Optional rank-agnostic arguments | ||
class(*), intent(in), optional, dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, & | ||
a11,a12,a13,a14,a15,a16,a17,a18, a19 | ||
|
||
character(32) :: code_msg | ||
|
||
write(code_msg, "('code - ', i0, ',')") code | ||
|
||
state = state_type(STDLIB_FS_ERROR, code_msg,a1,a2,a3,a4,a5,a6,a7,a8, & | ||
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18, a19) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The function signature spans multiple lines but lacks consistent spacing after commas. Consider adding spaces after commas for better readability: code, a1, a2, a3, ...
pure function fs_error_code(code,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, & | |
a11,a12,a13,a14,a15,a16,a17,a18, a19) result(state) | |
type(state_type) :: state | |
!> Platform specific error code | |
integer, intent(in) :: code | |
!> Optional rank-agnostic arguments | |
class(*), intent(in), optional, dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, & | |
a11,a12,a13,a14,a15,a16,a17,a18, a19 | |
character(32) :: code_msg | |
write(code_msg, "('code - ', i0, ',')") code | |
state = state_type(STDLIB_FS_ERROR, code_msg,a1,a2,a3,a4,a5,a6,a7,a8, & | |
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18, a19) | |
pure function fs_error_code(code, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, & | |
a11, a12, a13, a14, a15, a16, a17, a18, a19) result(state) | |
type(state_type) :: state | |
!> Platform specific error code | |
integer, intent(in) :: code | |
!> Optional rank-agnostic arguments | |
class(*), intent(in), optional, dimension(..) :: a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, & | |
a11, a12, a13, a14, a15, a16, a17, a18, a19 | |
character(32) :: code_msg | |
write(code_msg, "('code - ', i0, ',')") code | |
state = state_type(STDLIB_FS_ERROR, code_msg, a1, a2, a3, a4, a5, a6, a7, a8, & | |
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @wassup05 LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR @wassup05. I added a few comments.
Functions added are:
fs_error
: just sets theflag
ofstate_type
toSTDLIB_FS_ERROR
and passes the remaining 20 arguments to itfs_error_code
: sets theflag
as above and also prefixes thecode
(integer
argument) accordingly.I tried using an
interface
block to handle both of these together, but that introduces ambiguity for the compiler.Could make
code
anoptional
argument and depending on if it's present or not pass 18 or 20 arguments tostate_type
but I feel that the 2 unused arguments in that case would not be correct.Inspired from @perazz in #1006 (comment)